from typing import Any
from pydantic import BaseModel
from decimal import Decimal
from datetime import datetime

def json_serializer(obj: Any) -> Any:
    """自定义 JSON 序列化器"""
    if isinstance(obj, datetime):
        return obj.strftime("%Y-%m-%d %H:%M:%S")
    if isinstance(obj, Decimal):
        return float(obj) if obj is not None else None
    return str(obj)

class BaseSchema(BaseModel):
    """基础 Schema 类，所有的 schema 都应该继承这个类"""
    class Config:
        orm_mode = True  # 使用旧版的 orm_mode
        json_encoders = {
            datetime: lambda v: v.strftime("%Y-%m-%d %H:%M:%S") if v else None,
            Decimal: lambda v: float(v) if v is not None else None
        } 